/**
 * @className: HelloController
 * @description: Hello控制器
 * @date: 2020/4/19
 * @author: cakin
 */
package com.imooc.demo.controller;

import com.imooc.demo.common.Constant;
import com.imooc.demo.common.util.RequestIpUtils;
import com.imooc.demo.dto.UsDto;
import com.imooc.demo.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @className: HelloController
 * @description: Hello控制器
 * @date: 2020/4/19
 * @author: cakin
 */
@RestController
public class HelloController {

    /**
     * 定义日志
     */
    private Logger logger = Logger.getLogger(HelloController.class);


    /**
     * 注入userService
     */
    @Resource
    private UserService userService;

    @RequestMapping("/")
    public String index() {
        UsDto usDto = userService.doLogin(null);
        System.out.println(Constant.NUM1);
        return "Greetings from Spring Boot";
    }

    @RequestMapping("/hello")
    public String hello(HttpServletRequest req) {
        // 获取IP地址
        String ipAddr = RequestIpUtils.getIpAddr(req);
        System.out.println(ipAddr);
        return "hello Jenkins！Great！good！";
    }

    /**
     * 功能描述：日志测试
     * https://blog.csdn.net/m0_37063257/article/details/80400209
     *
     * @param
     * @return String
     * @author cakin
     * @date 2020/4/19
     * @description: 日志测试，输入到控制台和文件
     */
    @RequestMapping("/logtest")
    public @ResponseBody
    String helloWorld() {
        for (int i = 0; i < Constant.NUM2; i++) {
            logger.debug("debug" + i);
            logger.info("info" + i);
            logger.warn("warn" + i);
            logger.error("error" + i);
            logger.fatal("fatal" + i);
        }
        return "Hello World!";
    }
}
